package fluxo;

import java.io.*;
import java.net.*;
import java.util.Scanner;

public class Servidor {

	public static void main(String[] args) {
		try {
			ServerSocket server = new ServerSocket(5678);
			Socket clSocket = server.accept();
			InputStream in = clSocket.getInputStream();
			InputStreamReader isr = new InputStreamReader(in);
			BufferedReader reader = new BufferedReader(isr);
			String fName = reader.readLine();
			System.out.println(fName);
			File f1 = new File("/home/claudemir/servidor/" + fName);
			FileOutputStream out = new FileOutputStream(f1);

			int tamanho = 4096; // buffer de 4KB
			byte[] buffer = new byte[tamanho];
			int lidos = -1;
			while ((lidos = in.read(buffer, 0, tamanho)) != -1) {
				System.out.println(lidos);
				out.write(buffer, 0, lidos);
			}
			clSocket.close(); 
			out.flush();
		} catch (IOException e) {
		}
	}

}
